	$(function() {	 //友情链接
		//列表加载
		readListPage(currentPage);
	});

	var baseUrl = "";
	//当前显示第几页
	var currentPage=1;
	//一共多少页数据
	var totalPage;
	
	
	//产品列表
	function readListPage(pageNum){
		var read01 = $("#select_name").val();		//查询字段
		var data = {
			currentPage : pageNum,
			pageSize : 10,
			ready01 : read01,
		};
		$.ajax({
			url:baseUrl+'/fslinkController/selectPageQueryString',
			data : data,
			type : 'POST',
			dataType: "JSON",
			success : function(data) {
				var dataLists = null;
				if (data != null) {
					dataLists = data.dataList;
					var str="";
					if (dataLists != null) {
						//当前第几页
						currentPage=data.currentPage;
						//一共多少页数据
						totalPage=data.totalPage;
						for(var i=0;i<dataLists.length;i++){
							str+="<tr>"; 
							str+="<td>"; 
							str+="<input type=\"checkbox\" name=\"layTableCheckbox\" lay-skin=\"primary\" data_id=\""+ dataLists[i].id+"\">";
							str+="</div>";
							str+="</div>";
							str+="</td>";
							str+="<td>"+isNull(dataLists[i].name)+"</td>"; 
							str+="<td>"+isNull(dataLists[i].url)+"</td>"; 
							str+="<td>"+isNull(dataLists[i].remarks)+"</td>"; 
							str+="<td>"+isNull(dataLists[i].sort)+"</td>"; 
							str+="<td>"; 
							str+="<div class=\"btn-group\">"; 
							str+="<a class=\"btn btn-mini btn-success check_leaveMessage\" title=\"修改\"  onclick=\"readLineaskDetail('" + dataLists[i].id + "')\">修改</a>"; 
							str+="<a class=\"btn btn-mini btn-delete delete_content\" title=\"删除\" onclick=\"deleteById('" + dataLists[i].id + "')\">删除</a>"; 
							str+="</div>"; 
							str+="</td>"; 
							str+="</tr>"; 
						}
						//构建分页信息
						loadPage(data);
					}else{
						$("#page").text("");
						str+="<div class=\"context_item\">";
						str+="<div class=\"notdata\">暂无数据</div>";
						str+="</div>";
					}
					$("#lineask_table_list").html(str);
				}
			},
			error : function(error) {
				alert("获取询盘列表失败！");
			}
		});
	}
	
	
	//详情
	function readLineaskDetail(id){
		var data = {
				id : parseInt(id)
			};
			$.ajax({
				url:baseUrl+'/fslinkController/selectByPrimaryKey',
				data : data,
				type : 'POST',
				dataType: "JSON",
				success : function(result) {
					if(result!=null){
						$("#id").val(result.id);
						$("#name").val(result.name);
						$("#url").val(result.url);
						$("#remarks").val(result.remarks);
						$("#sort").val(result.sort);
					}else{
						$("#lineask_detail_time").html("暂无数据");
					}
			},
			error: function (result) {
			}
		});
	}
	
	
	//修改&&新增
	$(document).on("click",".span180",function(e){
		var id = $("#id").val();
		var name = $("#name").val();
		var url = $("#url").val();
		var remarks = $("#remarks").val();
		var sort = $("#sort").val();
		var data = {
				id:		id,
				name:	name,
				url:	url,
				remarks: 	remarks,
				sort:	sort
		}
		$.ajax({
			url:baseUrl+'/fslinkController/insertUpdate',
			data : data,
			type : 'POST',
			dataType: "JSON",
			success : function(result) {
				if(result!=null){
					if(result.state=="200"){
						//清除数据
						$("#id").val('');
						$("#name").val('');
						$("#url").val('');
						$("#remarks").val('');
						$("#sort").val('1');
						//跳转到列表页面
						$(".layui-tab ul li:first-child").click()
						readListPage(currentPage);
					}
				}
		},
		error: function (result) {
		}
	});
});
	
	
	//构建分页信息
	function loadPage(data){
		var pageStr = "";
		var pageNum = 0;
		var startindex = currentPage;  //当前页数
		var endindex = totalPage;  //总页数
		var spacenumb = endindex - startindex;
    	pageStr+="<div class=\"layui-box layui-laypage layui-laypage-default\" id=\"layui-laypage-1\">";
    	if(currentPage==1){
    		pageStr+="<a href=\"javascript:;\" class=\"layui-laypage-prev layui-disabled\"  id=\"prePage\">上一页</a>";
		}else{
			pageStr+="<a href=\"javascript:;\" class=\"layui-laypage-prev\"  id=\"prePage\">上一页</a>";
		}
    	if(currentPage==totalPage){
    		pageStr+="<a href=\"javascript:;\" class=\"layui-laypage-next layui-disabled\"   id=\"nextPage\">下一页</a>";
		}else{
			pageStr+="<a href=\"javascript:;\" class=\"layui-laypage-next\"   id=\"nextPage\">下一页</a>";
		}
    	pageStr+="<span class=\"layui-laypage-skip\">当前第 "+startindex+" 页";
    	pageStr+="</span>";
    	pageStr+="<span class=\"layui-laypage-limits\">合计"+data.totalPage+" 页 </span>";
    	pageStr+="<span class=\"layui-laypage-count\">共 "+data.totalRecord+" 条</span>";
    	pageStr+="</div>";
		$("#page").html(pageStr);
	}

	//上一页
	$(document).on("click","#prePage",function(){
		if(currentPage==1){
			alert("已经是第一页数据!");
			return false;
		}else{
			readListPage(currentPage-1);
		}
	});

	//下一页
	$(document).on("click","#nextPage",function(){
		if(currentPage==totalPage){
			alert("已经是最后一页数据!");
			return false;
		}else{
			readListPage(currentPage+1);
		}
	});

	//当前页数加载
	function pageNum(pageNum){
			loadCplbData(pageNum);
	}

	//判断为数据库null
	function isNull(reason){
		if(reason!=null&&reason!=""&&reason!="null"){
			return reason;
		}else{
			return "";
		}
	}
	
	
	//搜索按钮
	$(document).on("click",".btn-inverse",function(e){
		readListPage(currentPage);
	});
	
	//全部按钮
	$(document).on("click",".btn-success",function(e){
		$("#select_name").val('');  //设置查询条件为全部
		readListPage("1");
	});
	
	
	//删除单个
	function deleteById(id){
		if(confirm('确定删除该条内容吗？')) {
			deletePkId(id);
	      } else {
	        console.log('取消')
	        return;
	      }
	}
		
	
	//删除信息
	function deletePkId(id){
			$.ajax({
				url:baseUrl+'/fslinkController/deleteByPrimaryKey',
				data : {
					id:		id
				},
				type : 'POST',
				dataType: "JSON",
				success : function(result) {
					if(result.state=="200"){
						alert("删除成功。");
						readListPage("1");
					}else{
						alert("删除失败。");
					}
			},
			error: function (result) {
			}
		});
	}
	
	//返回按钮
	$(document).on("click","#return",function(e){
		$(".layui-tab ul li:first-child").click()
		readListPage(currentPage);
	});
	
